package com.hotel.tv.entities;

import lombok.Getter;
import lombok.Setter;

import javax.persistence.JoinColumn;
import javax.persistence.Table;
import java.math.BigDecimal;
import java.util.List;

/**
 * 用户订单
 * <p>
 * </p>
 *
 * @description TODO
 * @author: 老码农
 * @create: 2020-04-03 11:37
 **/
@Getter
@Setter
@Table(name = "b_order")
public class Order extends OrderBase {

    @JoinColumn(name = OrderItem.FIELD_ORDER_ID)
    private List<OrderItem> items;

    @Override
    public void forNullToDefault() {
        super.forNullToDefault();
        if (this.getItems() != null && this.getItems().size() > 0) {
            BigDecimal value = BigDecimal.ZERO;
            for (OrderItem item : this.getItems()) {
                value = value.add(item.getItemNumber());
            }
            this.setNumber(value);
        } else {
            this.setNumber(BigDecimal.ZERO);
        }
    }
}
